package ar.uade.edu.fain.ad.client.delegate.rmi;

import java.rmi.RemoteException;

import ar.uade.edu.fain.ad.client.delegate.EmpleadoServiceDelegate;
import ar.uade.edu.fain.ad.client.delegate.rmi.util.ServiceLocator;
import ar.uade.edu.fain.ad.client.exception.UnavailableServerException;
import ar.uade.edu.fain.ad.common.exception.AccesoDenegadoException;
import ar.uade.edu.fain.ad.common.remote.EmpleadoServicioRemoto;
import ar.uade.edu.fain.ad.common.transfer.LoginVO;

public class EmpleadoSRVD implements EmpleadoServiceDelegate {

	private ServiceLocator<EmpleadoServicioRemoto> locator;

	public EmpleadoSRVD(ServiceLocator<EmpleadoServicioRemoto> locator) {
		super();
		this.locator = locator;
	}

	public ServiceLocator<EmpleadoServicioRemoto> getLocator() {
		return locator;
	}

	public EmpleadoServicioRemoto getRemoteService()
			throws UnavailableServerException {
		return locator.getRemoteService();
	}

	@Override
	public LoginVO login(String username, String password)
			throws AccesoDenegadoException {
		try {
			return getRemoteService().login(username, password);
		} catch (RemoteException e) {
			throw new UnavailableServerException(
					"Error ejecutando remotamente.", e);
		} catch (UnavailableServerException e) {
			throw e;
		}
	}

}
